#include <tchar.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "GoogleService.hpp"
#include "GoogleReader.hpp"
#include "ReadDatabase.hpp"
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
	if(argc!=3) {
		_tprintf(_T("Invalid parameter!\n"));
		_tprintf(_T("%s [gmail_account] [password]\n"), argv[0]);
		return -1;
	}

	CGoogleReader Service(_T("M8-RSS Reader 1.0.1"));
	if(!Service.Auth(argv[1], argv[2])) {
		_tprintf(_T("error in auth\n"), argv[0]);
		return -1;
	}

#if 1
	CReaderDatabase::GetSingleton().Open("data.db");
	if(!CReaderDatabase::GetSingleton().Update(&Service)) {
		_tprintf(_T("update error\n"), argv[0]);
		return -1;
	}
	CReaderDatabase::GetSingleton().Close();
#endif

#if 0
	std::vector<Subscription> List;
	if(!Service.GetList(List)) {
		return -1;
	}

	std::vector<Item> Items;
	if(!Service.GetFeed("feed/http://feeds.feedburner.com/ixiqi", Items)) {
		return -1;
	}

	return 0;
#endif

#if 0
	TCHAR txt[1000];
	_stprintf(txt, _T("/reader/atom/%s"), _T("feed/http://feeds.feedburner.com/ixiqi"));
//	_tcscpy(txt, _T("/m8/feeds/contacts/default/full?max-results=1000"));

	CHAR szData[100*1024];
	DWORD dwDataSize = sizeof(szData);
	if(!Service.HttpGet(txt, szData, dwDataSize)) {
		return -1;
	}

	FILE* fp = fopen("sample.xml", "wt");
	fputs(szData, fp);
	fclose(fp);
#endif

	_tprintf(_T("done.\n"));
	return 0;
}
